package com.chenjt.netty.six_gPRC.streamResponse;

import com.chenjt.netty.six_gPRC.generateCode.*;
import io.grpc.stub.StreamObserver;

/**
 * 注释：
 *
 * @author chenjt
 * @date 2024/8/16 10:23
 */
public class StudentServiceImpl extends StudentServiceGrpc.StudentServiceImplBase {

    @Override
    public void getStudentsByAge(StudentRequest request, StreamObserver<StudentResponse> responseObserver) {
        System.out.println("接收到客户端信息：" + request.getAge());

        responseObserver.onNext(StudentResponse.newBuilder().setName("张三").setAge(20).setCity("北京").build());
        responseObserver.onNext(StudentResponse.newBuilder().setName("李四").setAge(30).setCity("天津").build());
        responseObserver.onNext(StudentResponse.newBuilder().setName("王五").setAge(40).setCity("成都").build());
        responseObserver.onNext(StudentResponse.newBuilder().setName("赵六").setAge(50).setCity("深圳").build());

        // 标识方法调用已经结束
        responseObserver.onCompleted();
    }
}
